
Public Class BloodResultHistory

    Protected _BloodAbnormalStatusHistory As New PoliceHealthClass.BloodAbnormalStatusHistory
    Protected _year As String
    Protected _hb As Double
    Protected _hct As Integer
    Protected _wbc As Integer
    Protected _neu As Integer
    Protected _eosin As Integer
    Protected _baso As Integer
    Protected _lymph As Integer
    Protected _mono As Integer
    Protected _plt As Integer
    Protected _police As New Police()
    Protected _blood_result_status As Boolean
    Protected _police_fullname As String
    Protected _police_age As Short
    Protected _Data As ArrayList
    Protected _DataCurrent As Integer

    Public Property police() As Police
        Get
            Return _police
        End Get
        Set(ByVal value As Police)
            _police = value
        End Set
    End Property

    Public Property police_fullname() As String
        Get
            Return _police_fullname
        End Get
        Set(ByVal value As String)
            _police_fullname = value
        End Set
    End Property

    Public Property police_age() As Short
        Get
            Return _police_age
        End Get
        Set(ByVal value As Short)
            _police_age = value
        End Set
    End Property

    Public Property baso() As Integer
        Get
            Return _baso
        End Get
        Set(ByVal value As Integer)
            _baso = value
        End Set
    End Property

    Public Property eosin() As Integer
        Get
            Return _eosin
        End Get
        Set(ByVal value As Integer)
            _eosin = value
        End Set
    End Property

    Public Property hb() As Double
        Get
            Return _hb
        End Get
        Set(ByVal value As Double)
            _hb = value
        End Set
    End Property

    Public Property hct() As Integer
        Get
            Return _hct
        End Get
        Set(ByVal value As Integer)
            _hct = value
        End Set
    End Property

    Public Property lymph() As Integer
        Get
            Return _lymph
        End Get
        Set(ByVal value As Integer)
            _lymph = value
        End Set
    End Property

    Public Property mono() As Integer
        Get
            Return _mono
        End Get
        Set(ByVal value As Integer)
            _mono = value
        End Set
    End Property

    Public Property neu() As Integer
        Get
            Return _neu
        End Get
        Set(ByVal value As Integer)
            _neu = value
        End Set
    End Property

    Public Property plt() As Integer
        Get
            Return _plt
        End Get
        Set(ByVal value As Integer)
            _plt = value
        End Set
    End Property

    Public Property wbc() As Integer
        Get
            Return _wbc
        End Get
        Set(ByVal value As Integer)
            _wbc = value
        End Set
    End Property

    Public Property year() As String
        Get
            Return _year
        End Get
        Set(ByVal value As String)
            _year = value
        End Set
    End Property

    Public Property blood_result_status() As Boolean
        Get
            Return _blood_result_status
        End Get
        Set(ByVal value As Boolean)
            _blood_result_status = value
        End Set
    End Property

    Public Function getPoliceCBCInOrganizationAll(ByVal inOrganizationID As String, ByVal inYear As String) As DataSet
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_PoliceBloodResultHistory"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inOrganizationID", inOrganizationID)
        objCmd.Parameters.Add(objParam)

        objParam = New MySql.Data.MySqlClient.MySqlParameter("inYear", inYear)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "PoliceCBC")

        Return objDs
    End Function

    Protected Function getsPoliceCBCInOrganizationAll(ByVal inOrganizationID As String, ByVal inYear As String) As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_PoliceBloodResultHistory"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inOrganizationID", inOrganizationID)
        objCmd.Parameters.Add(objParam)

        objParam = New MySql.Data.MySqlClient.MySqlParameter("inYear", inYear)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "PoliceBloodResult")

        For Each objDr As System.Data.DataRow In objDs.Tables("PoliceBloodResult").Rows
            Dim obj As BloodResultHistory = New BloodResultHistory
            obj.Police.citizen_id = objDr.Item("citizen_id")
            obj.police_fullname = objDr.Item("full_name")
            obj.Police.gender = objDr.Item("gender")
            obj.police_age = Utilities.ClearDBNullToMinValue(objDr.Item("age"), TypeCode.Int32)
            obj.hb = Utilities.ClearDBNullToMinValue(objDr.Item("hb"), TypeCode.Double)
            obj.hct = Utilities.ClearDBNullToMinValue(objDr.Item("hct"), TypeCode.Int32)
            obj.wbc = Utilities.ClearDBNullToMinValue(objDr.Item("wbc"), TypeCode.Int32)
            obj.neu = Utilities.ClearDBNullToMinValue(objDr.Item("neu"), TypeCode.Int32)
            obj.eosin = Utilities.ClearDBNullToMinValue(objDr.Item("eosin"), TypeCode.Int32)
            obj.baso = Utilities.ClearDBNullToMinValue(objDr.Item("baso"), TypeCode.Int32)
            obj.lymph = Utilities.ClearDBNullToMinValue(objDr.Item("lymph"), TypeCode.Int32)
            obj.eosin = Utilities.ClearDBNullToMinValue(objDr.Item("eosin"), TypeCode.Int32)
            obj.mono = Utilities.ClearDBNullToMinValue(objDr.Item("mono"), TypeCode.Int32)
            obj.plt = Utilities.ClearDBNullToMinValue(objDr.Item("plt"), TypeCode.Int32)
            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Public Function insertPoliceBloodResultHistory(ByVal inPoliceBloodResultHistory As BloodResultHistory) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_INSERT_PoliceBloodResultHistory"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inCitizenID", _
                Utilities.SendToDatabase(Utilities.ConvertCitizenID(inPoliceBloodResultHistory.police.citizen_id)))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inYear", _
                Utilities.SendToDatabase(inPoliceBloodResultHistory.year))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inOrganizationID", _
                Utilities.SendToDatabase(inPoliceBloodResultHistory.police.organization.organization_id))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inOrganizationNameTha", _
                Utilities.SendToDatabase(inPoliceBloodResultHistory.police.organization.organization_name_tha))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inHb", _
                Utilities.SendToDatabase(inPoliceBloodResultHistory.hb))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inHct", _
                Utilities.SendToDatabase(inPoliceBloodResultHistory.hct))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inWbc", _
                Utilities.SendToDatabase(inPoliceBloodResultHistory.wbc))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inNeu", _
                Utilities.SendToDatabase(inPoliceBloodResultHistory.neu))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inEosin", _
                Utilities.SendToDatabase(inPoliceBloodResultHistory.eosin))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inBaso", _
                Utilities.SendToDatabase(inPoliceBloodResultHistory.baso))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inLymph", _
                Utilities.SendToDatabase(inPoliceBloodResultHistory.lymph))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inMono", _
                Utilities.SendToDatabase(inPoliceBloodResultHistory.mono))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inPlt", _
                Utilities.SendToDatabase(inPoliceBloodResultHistory.plt))
            objCmd.Parameters.Add(objParam)

            _BloodAbnormalStatusHistory.deletePoliceBloodResultAbnormalStatus(inPoliceBloodResultHistory)
            If Not IsDBNull(Utilities.SendToDatabase(inPoliceBloodResultHistory.hb)) Then
                inPoliceBloodResultHistory.blood_result_status = _
                        _BloodAbnormalStatusHistory.insertPoliceBloodAbnormalStatusHistory(inPoliceBloodResultHistory)
                objParam = New MySql.Data.MySqlClient.MySqlParameter("inBloodResultStatus", _
                    Utilities.SendToDatabase(inPoliceBloodResultHistory.blood_result_status))
                objCmd.Parameters.Add(objParam)
            Else
                objParam = New MySql.Data.MySqlClient.MySqlParameter("inBloodResultStatus", DBNull.Value)
                objCmd.Parameters.Add(objParam)
            End If

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inCreateUser", _
                Utilities.SendToDatabase(inPoliceBloodResultHistory.police.create_user))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inUpdateUser", _
                Utilities.SendToDatabase(inPoliceBloodResultHistory.police.update_user))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inUpdateDate", _
                Utilities.ConvertDateTimeFormat(inPoliceBloodResultHistory.police.update_date.ToString()))
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Sub LoadPoliceCBCInOrganizationAll(ByVal inOrganizationID As String, ByVal inYear As String)
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getsPoliceCBCInOrganizationAll(inOrganizationID, inYear)
    End Sub

    Public Function NextRecord() As Boolean
        If ((Not _Data Is Nothing) AndAlso (((Not _Data Is Nothing) AndAlso _
            (_DataCurrent < _Data.Count And _Data.Count > 0)))) Then
            _police.citizen_id = _Data(_DataCurrent).police.citizen_id
            _police_fullname = _Data(_DataCurrent).police_fullname
            _police.gender = _Data(_DataCurrent).police.gender
            _police_age = _Data(_DataCurrent).police_age
            _hb = _Data(_DataCurrent).hb
            _hct = _Data(_DataCurrent).hct
            _wbc = _Data(_DataCurrent).wbc
            _neu = _Data(_DataCurrent).neu
            _eosin = _Data(_DataCurrent).eosin
            _baso = _Data(_DataCurrent).baso
            _lymph = _Data(_DataCurrent).lymph
            _eosin = _Data(_DataCurrent).eosin
            _mono = _Data(_DataCurrent).mono
            _plt = _Data(_DataCurrent).plt
            _DataCurrent += 1
            Return True
        End If
        Return False
    End Function

    Public Sub insertCBCSummaryReportValue(ByVal inYear As String, ByVal inOrganizationID As String)
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_INSERT_CBCSummaryReport"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inYear", inYear)
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inOrganizationID", inOrganizationID)
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Public Sub insertCBCAbnormalSummaryReportValue(ByVal inYear As String, ByVal inOrganizationID As String)
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_INSERT_CBCAbnormalSummaryReport"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inYear", inYear)
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inOrganizationID", inOrganizationID)
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

        Catch ex As Exception
            Throw ex
        End Try
    End Sub

End Class
